﻿using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using CuteRibs.D3Armory.Models;

namespace CuteRibs.D3Armory
{
	[ComVisible(true)]
	public class AppException : Exception
	{
		public AppException(Exception innerException, string url)
			: this(innerException)
		{
			this.Data["Url"] = url;
		}

		public AppException(Exception innerException, Realm realm, string battleTag)
			: this(innerException)
		{
			this.Data["Realm"] = realm.Region;
			this.Data["BattleTag"] = battleTag;
		}

		public AppException(Exception innerException, Realm realm, string battleTag, uint heroId)
			: this(innerException, realm, battleTag)
		{
			this.Data["HeroId"] = heroId;
		}

		private AppException(Exception innerException)
			: base(innerException.Message, innerException) { }

		public override string ToString()
		{
			var sb = new StringBuilder();
			sb.AppendLine();

			foreach (var p in this.Data.Keys.OfType<string>())
			{
				sb.AppendLine();
				sb.AppendFormat("{0}: {1}", p, this.Data[p]);
			}

			sb.AppendLine();
			return base.ToString() + sb.ToString();
		}
	}
}
